package de.tiw.common.xml;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class WSDL11Parser implements WParser {

	public List<String> getInterface(String WSDLFile) {
		// use jdom to parser wsdl file and get qname of port type
		List<String> qnames = new ArrayList<String>();
		Document doc = null;
		try {
			doc = DocumentHelper.parseText(WSDLFile);
		} catch (DocumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		// SAXReader sreader = new SAXReader();
		// try{
		// doc = sreader.read("sampleprocesses/sample.wsdl");
		// }catch(Exception e){
		// e.printStackTrace();
		// }
		// String xPath = "//Definitions//portType";
		// List<Node> ns = doc.selectNodes(xPath);
		Element e = doc.getRootElement();
		List<Element> es = e.elements("portType");
		// System.out.println(ns.size());
		// for (Node node : ns) {
		// String name = node.valueOf("@name");
		// System.out.println("the porttypes name is :" + name);
		// }
		Element root = doc.getRootElement();
		String tn = root.valueOf("@targetNamespace");
		//System.out.println("the target name is: " + tn);
		for (Element element : es) {
			qnames.add(tn + ":" + element.valueOf("@name"));
		}

		return qnames;
	}

}
